package cn.z2huo.knowledge.collection.enumset;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *
 * @author z2huo
 */
@Getter
@RequiredArgsConstructor
enum CompanyLevelEnum {

    HEAD_OFFice("1", "总部"),

    PROVINCE("2", "省公司"),

    CITY("3", "市公司"),

    COUNTY("4", "县公司"),

    ;

    private final String value;

    private final String name;

    public static final EnumSet<CompanyLevelEnum> EXCLUDE_HEAD_OFFICE = EnumSet.complementOf(EnumSet.of(HEAD_OFFice));

    public static final EnumSet<CompanyLevelEnum> NONE_ADMIN = EnumSet.range(CITY, COUNTY);

    private static final Map<String, CompanyLevelEnum> VALUE_ENUM_MAP = new HashMap<>(4);

    static {
        Arrays.stream(CompanyLevelEnum.values()).forEach(item -> VALUE_ENUM_MAP.put(item.getValue(), item));
    }

    public static CompanyLevelEnum fromValue(String value) {
        return VALUE_ENUM_MAP.get(value);
    }

    public static void main(String[] args) {
        System.out.println(EXCLUDE_HEAD_OFFICE);
        System.out.println(NONE_ADMIN);

        String companyLevel = "3";
        CompanyLevelEnum companyLevelEnum = CompanyLevelEnum.fromValue(companyLevel);
        if (NONE_ADMIN.contains(companyLevelEnum)) {
            System.out.println("当前登录人非总公司和省公司用户，不能配置管理员角色");
        }
    }

}
